<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">用户权益管理</ui:define>
    <ui:define name="content">
        <h:form>
            <p:dialog id="changeUserPrivilegeStatus" rendered="#{galaxyCardUserPrivilegeBean.chooseUserPrivilege != null}"
                      header="用户卡权益状态修改" position="center" widgetVar="userPrivilegeStatusDetail" modal="true" width="85%"
                      height="90%" responsive="true" footer="一般情况下不要修改用户权益为状态列表的前两个(0-等待生效|1-已生效)">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="chooseCardType" value="卡类型"/>
                    <p:inputText id="chooseCardType" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.cardType}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="chooseCardNo" value="卡号"/>
                    <p:inputText id="chooseCardNo" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.cardNo}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="chooseName" value="姓名"/>
                    <p:inputText id="chooseName" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.name}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="choosePhoneNumber" value="手机号码"/>
                    <p:inputText id="choosePhoneNumber" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.phoneNumber}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="chooseCardPrivilege" value="权益"/>
                    <p:inputText id="chooseCardPrivilege" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.privilege}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="choosePrivilegeStatus" value="权益状态"/>
                    <p:selectOneMenu id="choosePrivilegeStatus" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilege.privilegeStatus}" >
                        <f:selectItems
                                value="#{galaxyCardUserPrivilegeBean.choosePrivilegeStatuses}"
                                var="s" itemLabel="#{s.show}" itemValue="#{s.status}"/>
                    </p:selectOneMenu>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确认修改权益状态" actionListener="#{galaxyCardUserPrivilegeBean.onChangePrivilegeStatus()}"
                                     process="changeUserPrivilegeStatus" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="managePrivilegeExpress" rendered="#{galaxyCardUserPrivilegeBean.chooseUserPrivilege != null}"
                      header="用户卡权益-快递信息" position="center" widgetVar="managePrivilegeExpress" modal="true" width="85%"
                      height="90%" responsive="true" footer="如果用户未填写快递信息则以上信息显示为空">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="receiverName" value="收件人姓名"/>
                    <p:inputText id="receiverName" value="#{galaxyCardUserPrivilegeBean.express.receiverName}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="receiverPhone" value="收件人手机"/>
                    <p:inputText id="receiverPhone" value="#{galaxyCardUserPrivilegeBean.express.receiverPhone}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="receiverAddress" value="收件人地址"/>
                    <p:inputText id="receiverAddress" value="#{galaxyCardUserPrivilegeBean.express.getFullAddress()}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="expressNO" value="快递单号"/>
                    <p:inputText id="expressNO" value="#{galaxyCardUserPrivilegeBean.express.express_no}" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确认发货" actionListener="#{galaxyCardUserPrivilegeBean.onSendExpress()}"
                                     rendered="#{galaxyCardUserPrivilegeBean.chooseUserPrivilege.canSendExpress()}"
                                     process="managePrivilegeExpress" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="viewPrivilegeActiveCode" rendered="#{galaxyCardUserPrivilegeBean.cdKey != null}"
                      header="用户卡权益-激活码信息" position="center" widgetVar="viewPrivilegeActiveCode" modal="true" width="85%"
                      height="90%" responsive="true" footer="如用户已经领取激活码则可在此查看详情">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="cdKeyPrivilegeName" value="权益名称"/>
                    <p:inputText id="cdKeyPrivilegeName" value="#{galaxyCardUserPrivilegeBean.chooseUserPrivilegeResponse.privilege}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="cdKeyActiveCode" value="激活码"/>
                    <p:inputText id="cdKeyActiveCode" value="#{galaxyCardUserPrivilegeBean.cdKey.active_code}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="cdKeyActiveTime" value="激活时间"/>
                    <p:inputText id="cdKeyActiveTime" value="#{galaxyCardUserPrivilegeBean.cdKey.update_time}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="cdKeyImportTime" value="导入时间"/>
                    <p:inputText id="cdKeyImportTime" value="#{galaxyCardUserPrivilegeBean.cdKey.create_time}" readonly="true" style="width:100%"/>
                    <p:outputLabel for="cdKeyImportUserName" value="导入人员"/>
                    <p:inputText id="cdKeyImportUserName" value="#{galaxyCardUserPrivilegeBean.cdKey.operator_name}" readonly="true" style="width:100%"/>
                </p:panelGrid>
            </p:dialog>

            <p:dialog id="importPrivilegeCDKey" header="卡权益业务激活码导入" position="center" widgetVar="importPrivilegeCDKey" modal="true" width="85%"
                      height="90%" responsive="true" footer="在确认导入前请先选择权益,上传的Excel文件应只有一列,且此列从顶头开始应全部为激活码" closable="false">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="importPrivilegeCDKeyPrivilege" value="选择权益"/>
                    <p:selectOneMenu id="importPrivilegeCDKeyPrivilege" value="#{galaxyCardUserPrivilegeBean.importedCDKeyPrivilegeId}">
                        <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                        <f:selectItems  rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_SEARCH')}"
                                        value="#{galaxyCardUserPrivilegeBean.privileges}"
                                        var="p" itemLabel="#{p.name}" itemValue="#{p.id}"/>
                    </p:selectOneMenu>
                    <p:outputLabel for="importPrivilegeCDKeyFile" value="选择文件"/>
                    <p:fileUpload id="importPrivilegeCDKeyFile" fileUploadListener="#{galaxyCardUserPrivilegeBean.handleCDKeyImport}"
                            mode="advanced" auto="true" sizeLimit="#{constants:get('UPLOAD_FILE_SIZE')}" update="@this"
                                  allowTypes="/(\.|\/)(xlsx)$/" label="选择只包含一列的激活码EXCEL文件（.xlsx）" invalidFileMessage="文件格式不正确">
                        <p:outputLabel value="#{galaxyCardUserPrivilegeBean.importedCDKeyFileInfo}"/>
                    </p:fileUpload>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确认导入" actionListener="#{galaxyCardUserPrivilegeBean.onConfirmImportCDKeys()}"
                                     process="importPrivilegeCDKey" update="@form" />
                    <p:commandButton value="取消导入" actionListener="#{galaxyCardUserPrivilegeBean.onCancelImportCDKeys()}"
                                     process="importPrivilegeCDKey" update="@form" oncomplete="PF('importPrivilegeCDKey').hide()"/>
                </div>
            </p:dialog>

            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_SEARCH')}"
                                         icon="ui-icon-calculator"/>
                        <p:commandButton id="flush" value="刷新缓存" icon="fa fa-bolt"
                                         actionListener="#{galaxyCardUserPrivilegeBean.onFlushCache()}"
                                         update="@form"/>
                        <p:columnToggler datasource="userPrivilegeDataTable" trigger="toggler"/>

                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search" rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_SEARCH')}"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{galaxyCardUserPrivilegeBean.onReset}"
                                         process="@this"
                                         update="@form"/>
                        <p:commandButton icon="fa fa-upload" value="激活码导入" oncomplete="PF('importPrivilegeCDKey').show()"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">
                                <p:outputLabel for="privilege" value="权益"/>
                                <p:selectOneMenu id="privilege" value="#{galaxyCardUserPrivilegeBean.$.privilege}">
                                    <p:ajax event="change" listener="#{galaxyCardUserPrivilegeBean.onChoosePrivilege()}"
                                            update="@form"/>
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems  rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_SEARCH')}"
                                            value="#{galaxyCardUserPrivilegeBean.privileges}"
                                            var="p"
                                            itemLabel="#{p.name}" itemValue="#{p.id}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="status" value="权益状态"/>
                                <p:selectOneMenu id="status" value="#{galaxyCardUserPrivilegeBean.$.status}" >
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{galaxyCardUserPrivilegeBean.privilegeStatuses}"
                                            var="s"
                                            itemLabel="#{s.show}" itemValue="#{s.status}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="phoneNumber" value="手机号码"/>
                                <p:inputText id="phoneNumber" value="#{galaxyCardUserPrivilegeBean.$.phoneNumber}"/>

                                <p:outputLabel for="cardNo" value="黑卡卡号"/>
                                <p:inputText id="cardNo" value="#{galaxyCardUserPrivilegeBean.$.cardNo}"/>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="userPrivilegeDataTable"
                                         style="width: 100%"
                                         var="userPrivilege"
                                         value="#{galaxyCardUserPrivilegeBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{galaxyCardUserPrivilegeBean.selectedRecords}"
                                         rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_SEARCH')}"
                                         resizableColumns="true">
                                <p:column headerText="操作" rendered="#{security:areAllGranted('GALAXY_CARD_USER_PRIVILEGE_STATUS_EDIT')}">
                                    <p:splitButton icon="fa fa-pencil"
                                                   actionListener="#{galaxyCardUserPrivilegeBean.onChoosePrivilegeStatus(userPrivilege)}"
                                                   oncomplete="PF('userPrivilegeStatusDetail').show()"
                                                   process="@this" update="@form">
                                        <p:menuitem value="快递信息" icon="fa fa-truck" rendered="#{userPrivilege.expressId != null}"
                                                    actionListener="#{galaxyCardUserPrivilegeBean.onChoosePrivilegeStatus(userPrivilege)}"
                                                    oncomplete="PF('managePrivilegeExpress').show()"
                                                    process="@this" update="@form"/>
                                        <p:menuitem value="激活码" icon="fa fa-asterisk" rendered="#{userPrivilege.canShowCDKey()}"
                                                    actionListener="#{galaxyCardUserPrivilegeBean.onChoosePrivilegeStatus(userPrivilege)}"
                                                    oncomplete="PF('viewPrivilegeActiveCode').show()"
                                                    process="@this" update="@form"/>

                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="卡类型">
                                    <h:outputText value="#{userPrivilege.cardType}"/>
                                </p:column>
                                <p:column headerText="卡号" style="text-align:center">
                                    <h:outputText value="#{userPrivilege.cardNo}"/>
                                </p:column>
                                <p:column headerText="姓名">
                                    <h:outputText value="#{userPrivilege.name}"/>
                                </p:column>
                                <p:column headerText="手机号码" style="text-align:center">
                                    <h:outputText value="#{userPrivilege.phoneNumber}"/>
                                </p:column>
                                <p:column headerText="权益">
                                    <h:outputText value="#{userPrivilege.privilege}"/>
                                </p:column>
                                <p:column headerText="权益状态" style="text-align:center">
                                    <h:outputText value="#{userPrivilege.statusStr}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
